package com.bysc.commentservice.api;

import com.bysc.baseservice.handler.BaiYunException;
import com.bysc.commonutils.ResultCode;
import com.bysc.commonutils.Results;
import com.bysc.commonutils.constant.MessageConstant;
import com.bysc.commentservice.entity.vo.LikeVo;
import com.bysc.commentservice.service.GoodLikeApiService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@Api(tags = "前台点赞功能")
@RestController
@RequestMapping("/goodservice/good-like")
public class GoodLikeApiController {

    @Autowired
    private GoodLikeApiService goodLikeApiService;


    @ApiOperation(value = "点赞接口") //帖子，评论，回复评论，study
    @PostMapping("/likeCommentByToken")
    public Results likeCommentByToken(@ApiParam(name = "likeCommentVo", value = "点赞信息{文章id,文章type}", required = true)
                                      @RequestBody LikeVo likeVo, HttpServletRequest request) {
        try {

            goodLikeApiService.likeByToken(likeVo, request);
            return Results.ok().message(MessageConstant.LIKE_SUCCESS);
        } catch (Exception e) {
            throw new BaiYunException(ResultCode.ERROR, MessageConstant.LIKE_FAIL);
        }
    }

}
